//
//  ZDStoreHeader.m
//  ZDPension
//
//  Created by 刘甲奇 on 2017/6/15.
//  Copyright © 2017年 maker. All rights reserved.
//

#import "ZDStoreHeader.h"
#import "UIImageView+WebCache.h"

@interface ZDStoreHeader()

@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *storeNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *star1;
@property (weak, nonatomic) IBOutlet UIImageView *star2;
@property (weak, nonatomic) IBOutlet UIImageView *star3;
@property (weak, nonatomic) IBOutlet UIImageView *star4;
@property (weak, nonatomic) IBOutlet UIImageView *star5;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UILabel *serviceNumberLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;

@end
@implementation ZDStoreHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setStoreModel:(ZDStoreModel *)storeModel
{
    _storeModel = storeModel;
    NSString *imageUrl = [NSString stringWithFormat:@"http://58.57.98.122:81/shopnc_new/data/upload/shop/store/%@",storeModel.store_label];

    [self.icon sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"zwt"]];
    self.storeNameLabel.text = storeModel.store_name;
    self.scoreLabel.text = [NSString stringWithFormat:@"%@分",storeModel.store_credit_average];
    [self setCommitGrade:[storeModel.store_credit_average intValue]];
    self.addressLabel.text = [NSString stringWithFormat:@"%@ %@",storeModel.area_info,storeModel.store_address];
    self.serviceNumberLabel.text = storeModel.serviceNumber; 
    
}

#pragma mark- privateMethod

/**
 设置评分
 
 @param grade
 */
- (void)setCommitGrade:(int)grade
{
    UIImage *offImage = [UIImage imageNamed:@"b"];
    UIImage *onImage = [UIImage imageNamed:@"a"];
    
    switch (grade) {
        case 0:
        {
            [self setStarOff];
        }
            break;
        case 1:
        {
            
            self.star1.image = onImage;
            self.star2.image = offImage;
            self.star3.image = offImage;
            self.star4.image = offImage;
            self.star5.image = offImage;
        }
            break;
        case 2:
        {
            self.star1.image = onImage;
            self.star2.image = onImage;
            self.star3.image = offImage;
            self.star4.image = offImage;
            self.star5.image = offImage;
        }
            break;
        case 3:
        {
            self.star1.image = onImage;
            self.star2.image = onImage;
            self.star3.image = onImage;
            self.star4.image = offImage;
            self.star5.image = offImage;
        }
            break;
        case 4:
        {
            self.star1.image = onImage;
            self.star2.image = onImage;
            self.star3.image = onImage;
            self.star4.image = onImage;
            self.star5.image = offImage;
        }
            break;
        case 5:
        {
            self.star1.image = onImage;
            self.star2.image = onImage;
            self.star3.image = onImage;
            self.star4.image = onImage;
            self.star5.image = onImage;
        }
            break;
            
        default:
        {
            [self setStarOff];
        }
            break;
    }
}
- (void)setStarOff
{
    UIImage *offImage = [UIImage imageNamed:@"b"];
    self.star1.image = offImage;
    self.star2.image = offImage;
    self.star3.image = offImage;
    self.star4.image = offImage;
    self.star5.image = offImage;
}
- (IBAction)callClick:(UIButton *)sender
{
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",_storeModel.store_tel];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

@end
